import 'dart:io';
import 'dart:math';

void main() async {
  // Login().then((onValue){
  //   print(onValue);
  //   saveToken().then((onValue){
  //     print(onValue);
  //   }).catchError((onError){
  //     print(onError);
  //   });
  // }).catchError((onError){
  //   print(onError);
  // });

  try {
    final res = await Login();
    print(res);
    final res2 = await saveToken();
    print(res2);
  } catch (e) {
    print(e);
  }

  








}

Future<String> Login() {
  return Future(() {
    sleep(Duration(seconds: 2));
    var random = Random();
    final time = random.nextInt(10);
    if (time >= 2) {
      print(time);
      return "登录成功";
    } else {
      throw "登录失败";
    }
  });
}

Future<String> saveToken() {
  return Future(() {
    sleep(Duration(seconds: 2));
    var random = Random();
    final time = random.nextInt(10);
    if (time >= 5) {
      print(time);
      throw "token存储失败";
    }
    return "token存储成功";
  });
}
